// 封装全局 utils 函数
class Utils {
  // 获取当前时间
  getCurrentTime(format) {
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();
    const time = format
      .replace("YYYY", year)
      .replace("MM", month)
      .replace("DD", day)
      .replace("HH", hour)
      .replace("mm", minute)
      .replace("ss", second);
    return time;
  }
  // 获取当前时间戳
  getCurrentTimestamp() {
    return new Date().getTime();
  }
  // 获取当前日期
  getCurrentDate() {
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    return `${year}-${month}-${day}`;
  }
  // 判断是否是空对象
  isEmptyObject(obj) {
    return Object.keys(obj).length === 0;
  }
  // 判断是否是空数组
  isEmptyArray(arr) {
    return arr.length === 0;
  }
  // 判断是否是空字符串
  isEmptyString(str) {
    return str === "";
  }
  // 获取随机数
  getRandomNum(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
  }
  // 获取随机字符串,字母数字组合
  getRandomString(len) {
    const chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
    const maxPos = chars.length;
    let pwd = "";
    for (let i = 0; i < len; i++) {
      pwd += chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
  }
  // 获取随机颜色
  getRandomColor() {
    return `#${Math.random().toString(16).substr(-6)}`;
  }
  // 获取当前页面路由
  getCurrentPage() {
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    return currentPage;
  }
}

// module.exports = new Utils();
export default new Utils();
